#include <bits/stdc++.h>

class Solution {
private:
    int n, m, len, vLim;
    std::vector<int> d, v, a, p;
    std::vector<std::pair<int, int> > ranges, yaRanges; // [first, second)

    int search(int target, std::vector<int> &vec) { // >=
        int l = 0, r = vec.size();
        while (l < r - 1) {
            int mid = (l + r) / 2;
            if (vec[mid] >= target) {
                r = mid;
            } else {
                l = mid;
            }
        }
        return r;
    }

    std::pair<int, int> findPublic(std::pair<int, int> a, std::pair<int, int> b) {
        return std::make_pair(std::max(a.first, b.first), std::min(a.second, b.second));
    }

public:
    Solution(int n, int m, int len, int vLim, std::vector<int> &d, std::vector<int> &v, std::vector<int> &a, std::vector<int> &p) {
        this->n = n;
        this->m = m;
        this->len = len;
        this->vLim = vLim;
        this->d = d;
        this->v = v;
        this->a = a;
        this->p = p;

    }

    std::pair<int, int> solve() {
        ranges.resize(n);
        int lastStation = p.back();
        for (int i = 0; i < n; i++) {
            if (a[i] == 0) {
                if (v[i] > vLim) {
                    int id = search(d[i], p);
                    if (id >= m || id < 0) {
                        ranges[i] = std::make_pair(m, m);
                    } else {
                        ranges[i] = std::make_pair(id, m);
                    }
                } else {
                    ranges[i] = std::make_pair(m, m);
                }
            } else if (a[i] > 0) {
                int beyondPos = (vLim * vLim - v[i] * v[i]) / (2 * a[i]) + d[i] + 1;

                if (beyondPos > lastStation) {
                    ranges[i] = std::make_pair(m, m);
                } else {
                    int id = search(beyondPos, p);
                    if (id >= m || id < 0) {
                        ranges[i] = std::make_pair(m, m);
                    } else {
                        ranges[i] = std::make_pair(id, m);
                    }
                }
            } else {
                if (v[i] <= vLim) {
                    ranges[i] = std::make_pair(m, m);
                } else {
                    int lastPos = (vLim * vLim - v[i] * v[i]) / (2 * a[i]) + d[i];
                    int mod = (v[i] * v[i] - vLim * vLim) % (-2 * a[i]);
                    if (mod == 0) {
                        lastPos--;
                    }

                    if (lastPos < d[i]) {
                        ranges[i] = std::make_pair(m, m);
                    } else {
                        int id0 = search(d[i], p);
                        int id1 = search(lastPos, p);
                        if (p[id1] == lastPos) {
                            id1++;
                        }
                        ranges[i] = std::make_pair(std::max(0, id0), std::min(m, id1));
                    }
                }
            }
        }

        int res0 = 0;
        for (int i = 0; i < n; i++) {
            if (ranges[i].second - ranges[i].first > 0) {
                res0++;
                yaRanges.push_back(ranges[i]);
            }
        }

        int res1 = m;
        auto curRange = std::make_pair(0, m);
        int st = yaRanges[0].first;
        for (auto range: yaRanges) {
            auto myRange = findPublic(curRange, range);
            if (myRange.second - myRange.first <= 0) {
                res1--;
                curRange = std::make_pair(0, m);
            } else {
                curRange = myRange;
            }
        }
        return std::make_pair(res0, res1 - 1);
    }
};

int main() {
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    int t;
    std::cin >> t;
    for (int k = 0; k < t; k++) {
        int n, m, len, vLim;
        std::cin >> n >> m >> len >> vLim;
        std::vector<int> d(n), v(n), a(n), p(m);
        for (int i = 0; i < n; i++) {
            std::cin >> d[i] >> v[i] >> a[i];
        }
        for (int i = 0; i < m; i++) {
            std::cin >> p[i];
        }
        Solution sol(n, m, len, vLim, d, v, a, p);
        auto res = sol.solve();
        std::cout << res.first << " " << res.second << std::endl;
    }
    return 0;
}